﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Spinning.Spinning.Unitity;
using Microsoft.Xna.Framework.Input.Touch;

namespace Spinning.Spinning.Entity.Scenes
{
    class RoleScene : Scene
    {
        TextEntity scoreText;
        public override void OnLoad()
        {
            base.OnLoad();
            Sprite backGroundSprite = new Sprite();
            backGroundSprite.textureName = "role/interface01_bg";
            backGroundSprite.ZIndex = Constants.background;
            backGroundSprite.OnLoad();
            this.Attach(backGroundSprite);

            ButtonSprite storeSprite = new ButtonSprite();
            storeSprite.textureName = "role/btn_store";
            storeSprite.ZIndex = Constants.ui;
            storeSprite.Position = new Vector2(35, 530);
            storeSprite.OnLoad();
            TouchManager.RegisteTouchArea(storeSprite);
            this.Attach(storeSprite);

            ButtonSprite itemSprite = new ButtonSprite();
            itemSprite.textureName = "role/btn_items";
            itemSprite.ZIndex = Constants.ui;
            itemSprite.Position = new Vector2(245, 530);
            itemSprite.OnLoad();
            TouchManager.RegisteTouchArea(itemSprite);
            this.Attach(itemSprite);

            ButtonSprite single_pSprite = new ButtonSprite();
            single_pSprite.textureName = "role/btn_single_p";
            single_pSprite.ZIndex = Constants.ui;
            single_pSprite.Position = new Vector2(35, 530+120);
            single_pSprite.OnLoad();
            TouchManager.RegisteTouchArea(single_pSprite);
            this.Attach(single_pSprite);

            ButtonSprite two_pSprite = new ButtonSprite();
            two_pSprite.textureName = "role/btn_two_p";
            two_pSprite.ZIndex = Constants.ui;
            two_pSprite.Position = new Vector2(245, 530+120);
            two_pSprite.OnLoad();
            TouchManager.RegisteTouchArea(two_pSprite);
            this.Attach(two_pSprite);

            storeSprite.OnTouchEvent += OnStoreTouch;
            itemSprite.OnTouchEvent += OnItemTouch;


            scoreText = new TextEntity();
            ResourceManager.ContentRoot = "";
            scoreText.fontString = "Century Gothic";
            scoreText.OnLoad();
            scoreText.Scale = new Vector2(1.2f);
            scoreText.Origin = new Vector2(1);
            scoreText.Position = new Vector2(430, 505);
            scoreText.Color = Color.Black;
            //te.Alpha = 0;
            scoreText.ZIndex = Constants.ui;
            Attach(scoreText);
            scoreText.Value = "123";
        }

        int test = 0;
        protected override void UpdateSelf(Microsoft.Xna.Framework.GameTime gameTime)
        {
            test += 20;
            scoreText.Value = "" + test;
        }

        void OnStoreTouch(BaseEntity entity, TouchLocation touchLocation)
        {
            Game1.stageManager.GoToScene("store");
        }

        void OnItemTouch(BaseEntity entity, TouchLocation touchLocation)
        {
            Game1.stageManager.GoToScene("item");
        }

        public override Scene Clone()
        {
            Scene scene = new RoleScene();
            scene.Size = new Vector2(Constants.Window_Width, Constants.Window_Height);
            scene.OnLoad();
            scene.SortChildren();
            return scene;
        }
    }
}
